"""
CSPBuilder CSP XML functions

Copyright (c) 2008 Rune M. Friborg, runef@diku.dk.
See LICENSE.txt for licensing details (GPLv2).
"""

import xml.dom.minidom # xml parsing
import os

def parseFile(xmlFilename):
    return xml.dom.minidom.parse(xmlFilename) # DOM

def parseString(xmlString):
    return xml.dom.minidom.parseString(xmlString) # DOM

def createDom():
    return parseString("<doc></doc>");

def getAttrList(node):
    D = {}
    for i in range(node.attributes.length):
        D[node.attributes.item(i).name] = node.attributes.item(i).value
    return D

def getAttr(attr_list, attr_name):
    if (attr_list.has_key(attr_name)):
        return attr_list[attr_name]
    else:
        return None

def setAttr(node, attr_name, val):
    node.setAttribute(attr_name, str(val))

